package com.noble.mail.type.bean;

import com.noble.library.base.bean.BaseData;

import org.json.JSONObject;

/**
 * 消息返回解析
 */
public class MessageRet extends BaseData {

    public static final int MSG_CODE_BALANCE_INSUFFICIENT = -1;//余额不足或者不是VIP
    public static final int MSG_CODE_PULL_BLACK = -2;//已拉黑
    public static final int MSG_CODE_BALANCE_Y = -4;//Y币不够了
    public static final int MSG_CODE_OK = 0;//成功

    //{"d":3302,"msg_id":1166518,"s":0,"status":"ok","tm":1498109958}

    private long d;//本地消息ID
    private long msgId;//服务器消息ID
    private long tm;
    //    private boolean isOk;
    private int s;
    //170824 ADD START 打招呼提示使用消息体返回的错误信息
    private String fail_msg;//发送失败时的错误提示,只在s!=0时有效
    //170824 ADD END 打招呼提示使用消息体返回的错误信息

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);
        this.setD(jsonObject.optLong("d"));
        this.setMsgId(jsonObject.optLong("msg_id"));
//        String status = jsonObject.optString("status");
//        this.setOk("ok".equals(status));
        this.setTm(jsonObject.optLong("tm"));
        if (!jsonObject.isNull("s")) {//状态
            this.setS(jsonObject.optInt("s"));
        }
        //170824 ADD START 打招呼提示使用消息体返回的错误信息
        setFailMsg(jsonObject.optString("fail_msg"));
        //170824 ADD END 打招呼提示使用消息体返回的错误信息
    }

    public long getD() {
        return d;
    }

    public void setD(long d) {
        this.d = d;
    }

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    public long getTm() {
        return tm;
    }

    public void setTm(long tm) {
        this.tm = tm;
    }

//    public boolean isOk() {
//        return isOk;
//    }

//    public void setOk(boolean ok) {
//        isOk = ok;
//    }

    public int getS() {
        return s;
    }

    public boolean isS() {
        return s == MSG_CODE_OK;
    }

    public void setS(int s) {
        this.s = s;
    }

    //170824 ADD START 打招呼提示使用消息体返回的错误信息
    public String getFailMsg() {
        return fail_msg;
    }

    public void setFailMsg(String fail_msg) {
        this.fail_msg = fail_msg;
    }
    //170824 ADD END 打招呼提示使用消息体返回的错误信息
}